{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### r使\\不发生转义",
   "id": "ccb9222121ea1fa9"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-03-13T03:14:22.026554Z",
     "start_time": "2025-03-13T03:14:22.017461Z"
    }
   },
   "source": "print(f'this is \\n a line')",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is \n",
      " a line\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:15:15.244273Z",
     "start_time": "2025-03-13T03:15:15.237460Z"
    }
   },
   "cell_type": "code",
   "source": "print(r'this is a line with \\n')",
   "id": "377aa44e3389843d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "this is a line with \\n\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 自定义分隔符sep结束符end",
   "id": "67e0a193fe4d6ab8"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:17:07.574793Z",
     "start_time": "2025-03-13T03:17:07.551077Z"
    }
   },
   "cell_type": "code",
   "source": [
    "print(2025,3,27,sep='-')\n",
    "print(2025,3,13,end=' ')"
   ],
   "id": "9a33e1abcb14cd89",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-3-27\n",
      "2025 3 13 "
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 快读模板",
   "id": "8a291f018d49b90c"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:18:10.870415Z",
     "start_time": "2025-03-13T03:18:10.864506Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import sys\n",
    "input=lambda :sys.stdin.readline().strip()"
   ],
   "id": "6762342e53bceaa5",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### lambda",
   "id": "bb3cec13a4b66150"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:20:17.916456Z",
     "start_time": "2025-03-13T03:20:17.907051Z"
    }
   },
   "cell_type": "code",
   "source": [
    "get_mid=lambda nums:nums[len(nums)//2]\n",
    "print(get_mid([1,4,5]))"
   ],
   "id": "90ae7e9f7e0ce39a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "execution_count": 7
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### sorted()",
   "id": "b05c5c9b0652cbdd"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:21:43.788022Z",
     "start_time": "2025-03-13T03:21:43.772067Z"
    }
   },
   "cell_type": "code",
   "source": [
    "nums=[5,3,8,6,7]\n",
    "print(sorted(nums))\n",
    "print(sorted(nums,reverse=True))"
   ],
   "id": "d4814947567c3451",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 5, 6, 7, 8]\n",
      "[8, 7, 6, 5, 3]\n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:22:55.646374Z",
     "start_time": "2025-03-13T03:22:55.637067Z"
    }
   },
   "cell_type": "code",
   "source": [
    "words=[\"ma\",\"jia\",\"qi\"]\n",
    "print(sorted(words,key=len))  #按字符串长度排序"
   ],
   "id": "c9cd1b425fe10e9e",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ma', 'qi', 'jia']\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:24:33.234165Z",
     "start_time": "2025-03-13T03:24:33.215923Z"
    }
   },
   "cell_type": "code",
   "source": [
    "words=[\"ma\",\"jia\",\"qi\"]\n",
    "sorted_words=sorted(words,key=lambda x:x[1])\n",
    "print(sorted_words)  #按第二个字符排序"
   ],
   "id": "d072fb72d91a5d94",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['ma', 'jia', 'qi']\n"
     ]
    }
   ],
   "execution_count": 12
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 输入",
   "id": "34b1cba62338c107"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "a,b,c=map(int,input().split())\n",
    "print(a,b,c)"
   ],
   "id": "7097cbf1d6e131cb",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "n=3\n",
    "lst=[int(input()) for _ in range(n)]"
   ],
   "id": "649bdcf05ac436f3",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "n,m=map(int,input().split())\n",
    "matrix=[list(map(int,input().split())) for _ in range(n)]"
   ],
   "id": "d863a4c48e880758",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 列表推导器",
   "id": "30a4c57c89f1b12"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:31:38.469623Z",
     "start_time": "2025-03-13T03:31:38.452072Z"
    }
   },
   "cell_type": "code",
   "source": [
    "square=[i**2 for i in range(1,11)]\n",
    "print(square)"
   ],
   "id": "646941fcb2f2e474",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n"
     ]
    }
   ],
   "execution_count": 19
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:32:22.380589Z",
     "start_time": "2025-03-13T03:32:22.365971Z"
    }
   },
   "cell_type": "code",
   "source": [
    "evens=[i for i in range(1,21) if i%2==0]\n",
    "print(evens)"
   ],
   "id": "7d42c4844d10e2df",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]\n"
     ]
    }
   ],
   "execution_count": 20
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:33:52.988667Z",
     "start_time": "2025-03-13T03:33:52.976703Z"
    }
   },
   "cell_type": "code",
   "source": [
    "input_data=list[map(int,input().split())]\n",
    "#等价于\n",
    "input_data=[int(x) for x in input().split()]"
   ],
   "id": "46b32fdad13f0990",
   "outputs": [],
   "execution_count": 22
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "61f15bd2bd99324a"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "#n*n矩阵",
   "id": "af3a1344d35183ff"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:35:39.596002Z",
     "start_time": "2025-03-13T03:35:39.582469Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n=3\n",
    "zero_matrix=[[0 for _ in range(n)] for _ in range(n)]\n",
    "print(zero_matrix)"
   ],
   "id": "89d4f81d66dce9ea",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n"
     ]
    }
   ],
   "execution_count": 26
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:37:33.908420Z",
     "start_time": "2025-03-13T03:37:33.891688Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#快速生成斐波那契数列\n",
    "n=10\n",
    "fib=[0,1]\n",
    "[fib.append(fib[-1]+fib[-2]) for _ in range(n-2)]\n",
    "print(fib)"
   ],
   "id": "2207ae9e61035a8d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\n"
     ]
    }
   ],
   "execution_count": 27
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "",
   "id": "8f29ebf824c1df45"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:39:09.640480Z",
     "start_time": "2025-03-13T03:39:09.631866Z"
    }
   },
   "cell_type": "code",
   "source": [
    "#二位列表展平为一维列表\n",
    "matrix=[[1,2,3],[4,5,6],[7,8,9]]\n",
    "flatten=[x for row in matrix for x in row]\n",
    "print(flatten)"
   ],
   "id": "a3e4903c658ccb7c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "execution_count": 28
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### range()函数",
   "id": "16e86c524922eb67"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:39:52.370542Z",
     "start_time": "2025-03-13T03:39:52.361799Z"
    }
   },
   "cell_type": "code",
   "source": [
    "seq=range(10)\n",
    "print(list(seq))"
   ],
   "id": "5d6539162431419a",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "execution_count": 29
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:40:35.884101Z",
     "start_time": "2025-03-13T03:40:35.871446Z"
    }
   },
   "cell_type": "code",
   "source": [
    "seq=range(1,11,2)\n",
    "print(list(seq))"
   ],
   "id": "b944105226b05634",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 3, 5, 7, 9]\n"
     ]
    }
   ],
   "execution_count": 31
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:41:09.269261Z",
     "start_time": "2025-03-13T03:41:09.254591Z"
    }
   },
   "cell_type": "code",
   "source": [
    "seq = range(10,0,-1)\n",
    "print(list(seq))"
   ],
   "id": "1271869eb72734dc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:41:59.733784Z",
     "start_time": "2025-03-13T03:41:59.721372Z"
    }
   },
   "cell_type": "code",
   "source": [
    "n=5\n",
    "for i in range(n*2): #*是重复\n",
    "    idx=i%n\n",
    "    print(idx,end=' ')"
   ],
   "id": "1b2407376ba2d681",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 2 3 4 0 1 2 3 4 "
     ]
    }
   ],
   "execution_count": 33
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 队列 先进先出",
   "id": "5485967025555db4"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "from collections import deque\n",
    "q=deque()\n",
    "q.append(x)\n",
    "#q.appendleft(x)\n",
    "x=q.popleft()\n",
    "len(q)"
   ],
   "id": "d08835339a9ca3e9",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:44:05.098427Z",
     "start_time": "2025-03-13T03:44:05.084389Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from collections import deque\n",
    "q=deque()\n",
    "q.append(5)\n",
    "q.append(6)\n",
    "#q.appendleft(x)\n",
    "x=q.popleft()\n",
    "len(q)"
   ],
   "id": "e08240318d892b8",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 36
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "#### 栈 先进后出",
   "id": "2a6e0578a53ba8fe"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "stk=[]\n",
    "stk.append(x)\n",
    "x=stk.pop()\n",
    "stk[-1]"
   ],
   "id": "ef579e58c883c415"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T03:45:17.034029Z",
     "start_time": "2025-03-13T03:45:17.021233Z"
    }
   },
   "cell_type": "code",
   "source": [
    "stk=[]\n",
    "stk.append(3)\n",
    "stk.append(27)\n",
    "x=stk.pop()\n",
    "stk[-1]"
   ],
   "id": "f41a3d01f133c17d",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 38
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "if not q:#判空\n",
    "    stack[::-1]  #逆序"
   ],
   "id": "ad4fd239bc8ff1c5"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T12:22:33.788462Z",
     "start_time": "2025-03-13T12:22:33.778829Z"
    }
   },
   "cell_type": "code",
   "source": [
    "nums=[[0,0]]*3\n",
    "print(nums)\n",
    "a,b=[0]*3,[0]*3\n",
    "print(a,b)"
   ],
   "id": "dee1779f285daa32",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0, 0], [0, 0], [0, 0]]\n",
      "[0, 0, 0] [0, 0, 0]\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-03-13T14:44:03.378304Z",
     "start_time": "2025-03-13T14:44:03.369325Z"
    }
   },
   "cell_type": "code",
   "source": "print(3%1)",
   "id": "4b5423da0367cafd",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "import os\n",
    "import sys\n",
    "\n",
    "# 请在此输入您的代码\n",
    "input=lambda:sys.stdin.readline().strip()\n",
    "t=int(input())\n",
    "for _ in range(t):\n",
    "    n,num=map(int,input().split())\n",
    "    list1=[]\n",
    "    x=0\n",
    "    for i in range(2,n):\n",
    "        if n%i==0:\n",
    "            list1.append(i)\n",
    "    for j in list1:\n",
    "        x+=j\n",
    "    min_num=min(x,n)\n",
    "    list2=[]\n",
    "    for k in range(2,min_num):\n",
    "        if x%k==0 and n%k==0:\n",
    "            list2.append(k)\n",
    "    res=x*n\n",
    "    if len(list2) !=0:\n",
    "        for i in range(2,len(list2)):\n",
    "            res=res/list2[i]\n",
    "    if res==num:\n",
    "        print('YES')\n",
    "    else:\n",
    "        print('NO')\n"
   ],
   "id": "62c8fdc1973f462b"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
